<?php
	 /*  error_reporting(E_ALL);
          ini_set("display_errors", 1); */
		  
/* #############################################################################################
   @Modulo Phone Payment 
   # Autor: Walter Hernandez 
   # e-mail: info@goldenfoxi.com 
   # web : wwww.goldenfoxi.com 
   ##################### copyright www.goldenfoxi.com - 2012 - ################################## */ 
   
	include(dirname(__FILE__).'/../../config/config.inc.php');
	include(dirname(__FILE__).'/../../header.php');
	include(dirname(__FILE__).'/phonepayment.php');
	
	$context = Context::getContext();
	
	$cart = $context->cart;
	
	$phonepayment = new PhonePayment();


  if ($cart->id_customer == 0 
     OR $cart->id_address_delivery == 0 
	 OR $cart->id_address_invoice == 0 
	 OR !$phonepayment->active) Tools::redirect('index.php?controller=order&step=1');
	
	 $authorized = false;
	       foreach (Module::getPaymentModules() as $module)
		      if ($module['name'] == 'phonepayment')
		           {
			          $authorized = true;
			        break;
	             }
	  
  if (!$authorized) die($phonepayment->l('Este medio de pago No esta disponible!', 'validation'));
	 
	 $customer = new Customer((int)($cart->id_customer));
	 
	 if (!Validate::isLoadedObject($customer))Tools::redirect('index.php?controller=order&step=1');

     $currency = $context->currency;
   
     $total = (float)($cart->getOrderTotal(true, Cart::BOTH));

$phonepayment->validateOrder($cart->id, Configuration::get('PS_OS_PHONEPAYMENT'), $total, $phonepayment->displayName, NULL, array(), (int)$currency->id, false, $customer->secure_key);

$order = new Order($phonepayment->currentOrder);
Tools::redirect('index.php?controller=order-confirmation&id_cart='.$cart->id.'&id_module='.$phonepayment->id.'&id_order='.$phonepayment->currentOrder.'&key='.$customer->secure_key);

?>